package com.opgea.crm.services.security;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.opgea.crm.common.vo.GroupVo;
import com.opgea.crm.domain.entities.security.Group;
import com.opgea.crm.domain.modal.QualifierModel;
import com.opgea.crm.repository.security.GroupRepository;

@Service
public class GroupServiceImpl implements GroupService{

	@Autowired
	GroupRepository groupRepository;
	
	public void create(Group group) {
		groupRepository.create(group);
	}

	public Group find(Long id) {
		return groupRepository.find(id);
	}

	public List<Group> findAll() {
		return groupRepository.findAll();
	}
	
	public List<QualifierModel> findAllGroupNames(){
		List<Group> groups = groupRepository.findAll();
		List<QualifierModel> groupList = new ArrayList<QualifierModel>();
		for(Group group : groups){
			groupList.add(new QualifierModel(group.getId(), group.getName()));
		}
		return groupList;
	}
	
	public List<GroupVo> findAllGroup() {
		List<Group> groups = groupRepository.findAll();
		List<GroupVo> groupList = new ArrayList<GroupVo>();
		for(Group group : groups){
			groupList.add(new GroupVo(group.getId(), group.getName()));
		}
		return groupList;
	}	

	public void update(Group group) {
		groupRepository.update(group);
	}

	public void remove(Long id) {
		groupRepository.remove(id);
	}
}
